package com.thwcompany.service;
import cn.hutool.core.date.DateUtil;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;
/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2022/10/21  20:38
 * @Description:
 */
@RabbitListener(queues = "business.queue1")
@Service
public class BusinessReceiveService {

    @SneakyThrows
    @RabbitHandler
    public void receive(String msg, Channel channel, Message message) {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //接收消息
        //channel.basicAck(deliveryTag,false);
        //System.out.println(" >>> 消费者确认的业务消息：" + msg);

        // 拒绝消息
        channel.basicNack(deliveryTag, false, false);
        String format = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss.SSS");
        System.out.println(format+" >>> 消费者拒绝的业务消息：" + msg);
    }
}
